import { useState } from 'react'

// 子组件
function Son(params) {
	const { getMsg } = params

	// 子传父：子组件调用父组件传递过来的函数来传递数据过去

	return (
		<>
			<h1>Son</h1>
			<button onClick={() => getMsg('Hello, I am a son')}>点击我给父组件传值</button>
		</>
	)
}

// 父组件
function Father() {
	const [msg, setMsg] = useState('')

	const getMsg = (msg) => {
		setMsg(msg)
	}

	return (
		<>
			<h2>Father</h2>
			<p>子组件传递过来的消息：{msg}</p>

			<hr />

			<Son getMsg={getMsg} />
		</>
	)
}

export default Father
